package Text1;

import java.util.*;

public class Main {
    //    n−皇后问题是指将n个皇后放在 n×n 国际象棋棋盘上，
//    使得皇后不能相互攻击到，即任意两个皇后都不能处于同一行、同一列或同一斜线上。
    static int N = 20, n;
    static char[][] g = new char[N][N];
    static boolean[] col = new boolean[N];
    static boolean[] p1 = new boolean[N];
    static boolean[] p2 = new boolean[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            Arrays.fill(g[i], '.');
        }
        dfs(0);
    }

    private static void dfs(int u) {
        if (u == n) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print(g[i][j]);
                }
                System.out.println();
            }
            System.out.println();
        }

        for (int i = 0; i < n; i++) {
            if (!col[i] && !p1[u + i] && !p2[n - u + i]) {
                g[u][i] = 'Q';
                col[i] = p1[u + i] = p2[n - u + i] = true;
                dfs(u+1);
                g[u][i] = '.';
                col[i] = p1[u + i] = p2[n - u + i] = false;
            }
        }
    }
}
